package com.ushine.design.jdk8.lambda;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class JDK8_Collection {
    public static void main(String[] args) {
        List<String> test7 = new ArrayList<String>();
        test7.add("Google");
        test7.add("Runoob");
        test7.add("Taobao");
        test7.add("Baidu");
        test7.add("sina");
        JDK8_Collection collection_jdk7 = new JDK8_Collection();
        System.out.println("jdk7的语法：");
        collection_jdk7.sortStringJdk7(test7);
        System.out.println(test7);

        List<String> test8 = new ArrayList<String>();
        test8.add("Google");
        test8.add("Runoob");
        test8.add("Taobao");
        test8.add("Baidu");
        test8.add("sina");
        JDK8_Collection collection_jdk8 = new JDK8_Collection();
        System.out.println("jdk8的语法：");
        collection_jdk8.sortStringJdk8(test8);
        System.out.println(test8);

    }

    /**
     * jdk7
     *
     * @param list
     */
    private void sortStringJdk7(List<String> list) {
        Collections.sort(list, new Comparator<String>() {

            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
    }

    /**
     * jdk8
     *
     * @param list
     */
    private void sortStringJdk8(List<String> list) {
        Collections.sort(list, (o1, o2) -> o1.compareTo(o2));
    }
}
